package com.x.bpm.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.bpm.dao.BpmDao;
import com.x.bpm.manage.BpmManage;
import com.x.bpm.model.*;
import com.x.bpm.rpc.BpmRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by x on 2017/11/13.
 */
@Component
@Service(interfaceName = "com.x.bpm.rpc.BpmService", timeout = 10000)
public class BpmService extends BaseService implements BpmRpcService {

    @Autowired
    private BpmManage bpmManage;

    @Autowired
    private BpmDao bpmDao;

    @Override
    public List<Operation> selectOperationList(StateMap stateMap, Rule rule) {
        try {
            return bpmManage.selectOperationList(stateMap, rule);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    @Override
    public List<StateEnum> selectStateEnumLis(State state) {
        try {
            return bpmDao.selectStateEnumLis(state);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    @Override
    public void insertInstance(Instance instance, StateEnum ... stateEnums) {
        try {
            bpmManage.insertInstance(instance, stateEnums);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

}
